package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.query.DestinationQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.uitl.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("destination")
public class DestinationController {
    @Autowired
    private IDestinationService destinationService;
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo){
       Page<Destination> page =destinationService.query(qo);
       model.addAttribute("page",page);
       //共享toasts,拿到跟
        model.addAttribute("toasts",destinationService.createTost(qo.getParentId()));
        //直接返回页面
        return "destination/list";
    }
    /**
     * 通过区域id删除数据
     * @par
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        destinationService.delete(id);
        return JsonResult.success();
    }
    @RequestMapping("/updateInfo")
    @ResponseBody
    public JsonResult updateInfo(String id ,String info){
            //1先查询  2再替换  3修改
        Destination destination = destinationService.get(id);
        destination.setInfo(info);
        destinationService.update(destination);

       return JsonResult.success();
    }
}
